package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark57Binding;

import java.util.ArrayList;

public class Mark57 extends BaseMark {

    LayoutWatermark57Binding binding;

    public Mark57(@NonNull Context context) {
        super(context);
    }

    public Mark57(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark57(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark57Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark57Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title57", binding.binding1);
        setText(binding.binding3, "no57", binding.binding2);
        setText(binding.binding5, "count57", binding.binding4);
        setText(binding.binding7, "area57", binding.binding6);
        setText(binding.binding9, "content57", binding.binding8);
        setText(binding.binding11, "worker57", binding.binding10);
        setText(binding.binding13, "charge57", binding.binding12);
        setText(binding.binding15, "weather57", binding.binding14);
        setText(binding.binding17, "didian57", "在这里", binding.binding16);
        setText(binding.binding19, "height57", binding.binding18);
        setText(binding.binding21, "angle57", binding.binding20);
        setText(binding.binding23, "speed57", binding.binding22);
        setText(binding.binding25, "jingwei57", binding.binding24);
        String[] ss = new EditItem("jingwei57").getStringPoints();
        binding.binding25.setText(ss[1]);
        binding.binding27.setText(ss[0]);
        setText(binding.binding29, "beizhu57", binding.binding28);
        setText(binding.binding31, "build57", binding.binding30);

        setText(binding.binding33, "jianlidanwei57", binding.binding32);
        setText(binding.binding35, "shigongdanwei57", binding.binding34);
        setText(binding.binding37, "shejidanwei57", binding.binding36);
        setText(binding.binding39, "kanchadanwei57", binding.binding38);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title57", "标题"));
        list.add(new EditItem("no57", "编号"));
        list.add(new EditItem("count57", "计数"));

        list.add(new EditItem("area57", "施工区域"));
        list.add(new EditItem("content57", "施工内容"));
        list.add(new EditItem("worker57", "施工责任人"));
        list.add(new EditItem("charge57", "监理责任人"));
        list.add(new EditItem("weather57", "天气"));

        list.add(new EditItem("didian57", "地点"));
        list.add(new EditItem("height57", "海拔"));
        list.add(new EditItem("angle57", "方位角"));
        list.add(new EditItem("speed57", "速度"));

        list.add(new EditItem("jingwei57", "经纬度"));

        list.add(new EditItem("beizhu57", "备注"));

        list.add(new EditItem("build57", "建设单位"));
        list.add(new EditItem("jianlidanwei57", "监理单位"));
        list.add(new EditItem("shigongdanwei57", "施工单位"));
        list.add(new EditItem("shejidanwei57", "设计单位"));
        list.add(new EditItem("kanchadanwei57", "勘察单位"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if ("jingwei57".equals(item.key)) {
            String[] ss = new EditItem("jingwei57").getStringPoints();
            binding.binding25.setText(ss[1]);
            binding.binding27.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if ("jingwei57".equals(item.key)) {
            if (item.show) {
                showView(binding.binding24, binding.binding26);
            } else {
                hideView(binding.binding26, binding.binding24);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
